<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="教师id" prop="teacherId">
        <el-input v-model="queryParams.teacherId" placeholder="请输入教师id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <!-- <el-form-item label="上课班级id" prop="courseclassId">
        <el-input v-model="queryParams.courseclassId" placeholder="请输入上课班级id" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="评价成绩" prop="evaluationScore">
        <el-input v-model="queryParams.evaluationScore" placeholder="请输入评价成绩" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['niuyabo:CourseclassTeacher:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['niuyabo:CourseclassTeacher:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['niuyabo:CourseclassTeacher:remove']">删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['score:courseclassTeacher:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="CourseclassTeacherList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="教师id" align="center" prop="teacherId" /> -->
      <el-table-column label="教师" align="center" prop="teacher.realName" />
      <!-- <el-table-column label="上课班级id" align="center" prop="courseclassId" /> -->
      <el-table-column label="上课班级编号" align="center" prop="courseclass.courseclassNo" />
      <el-table-column label="课程" align="center" prop="courseclass.course.courseName" />
      
      <el-table-column label="评价成绩" align="center" prop="evaluationScore" />
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['niuyabo:CourseclassTeacher:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['niuyabo:CourseclassTeacher:remove']">删除</el-button>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
		 
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleSelectStudent(scope.row)"
            v-hasPermi="['score:courseclassTeacher:edit']">查看学生列表</el-button>
          <!-- <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['niuyabo:CourseclassTeacher:remove']">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

      <!-- 查看学生列表对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="上课班级" prop="courseclassId">
          <el-select v-model="form.courseclassId" filterable placeholder="请选择上课班级">
            <el-option v-for="item in courseclassList" :key="item.courseclassId" :label="item.courseclassNo"
              :value="item.courseclassId" :disabled="item.status == 1"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="上课教师" prop="teacherId">
          <el-select v-model="form.teacherId" filterable placeholder="请选择上课教师">
            <el-option v-for="item in teacherList" :key="item.teacherId" :label="item.realName"
              :value="item.teacherId" :disabled="item.status == 1"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="评价成绩" prop="evaluationScore">
          <el-input v-model="form.evaluationScore" placeholder="请输入评价成绩" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改教师上课对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="上课班级" prop="courseclassId">
          <el-select v-model="form.courseclassId" filterable placeholder="请选择上课班级">
            <el-option v-for="item in courseclassList" :key="item.courseclassId" :label="item.courseclassNo"
              :value="item.courseclassId" :disabled="item.status == 1"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="上课教师" prop="teacherId">
          <el-select v-model="form.teacherId" filterable placeholder="请选择上课教师">
            <el-option v-for="item in teacherList" :key="item.teacherId" :label="item.realName"
              :value="item.teacherId" :disabled="item.status == 1"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="评价成绩" prop="evaluationScore">
          <el-input v-model="form.evaluationScore" placeholder="请输入评价成绩" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import { listCourseclassTeacher, getCourseclassTeacher, delCourseclassTeacher, addCourseclassTeacher, updateCourseclassTeacher, getCourseclassTeacherAndStudent } from "@/api/score/CourseclassTeacher";
// import { listCourseclass } from "@/api/niuyabo/courseclass";
import { listTeacher } from "@/api/score/teacher";
export default {
  name: "CourseclassTeacher",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 教师上课表格数据
      CourseclassTeacherList: [],
      // 课程班级表格数据
      courseclassList: [],
      // 教师管理表格数据
      teacherList: [],
      // // 学生表格数据
      // CourseclassTeacherAndStudent: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        teacherId: null,
        courseclassId: null,
        evaluationScore: null,
		userId:this.$store.getters.userId,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询教师上课列表 */
    getList() {
      this.loading = true;
	  console.log(this.queryParams)
      listCourseclassTeacher(this.queryParams).then(response => {
        this.CourseclassTeacherList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      /** 查询课程班级列表 */
      // listCourseclass().then(response => {
      //   this.courseclassList = response.rows;
      //   // this.total = response.total;
      //   // this.loading = false;
      // });
      /** 查询教师管理列表 */
      listTeacher(this.queryParams).then(response => {
        this.teacherList = response.rows;
        // this.total = response.total;
        // this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        teacherId: null,
        courseclassId: null,
        evaluationScore: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.teacherId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加教师上课";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const teacherId = row.teacherId || this.ids
      getCourseclassTeacher(teacherId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改教师上课";
      });
    },
    /** 查看学生列表操作 */
    handleSelectStudent(row) {
      // this.reset();
      // const courseclassId  = row.courseclassId
      // getCourseclassTeacherAndStudent(courseclassId).then(response => {
      //   this.form = response.data;
      //   // this.CourseclassTeacherAndStudent = response.data; 
      //   this.open = true;
      //   this.title = "查看学生列表";
      // });
      const courseclassId = row.courseclassId;
	  console.log(courseclassId)
      this.$router.push("/score/courseclass-students/courseclass/" + courseclassId);
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.teacherId != null) {
            updateCourseclassTeacher(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCourseclassTeacher(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const teacherIds = row.teacherId || this.ids;
      this.$modal.confirm('是否确认删除教师上课编号为"' + teacherIds + '"的数据项？').then(function () {
        return delCourseclassTeacher(teacherIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('score/CourseclassTeacher/export', {
        ...this.queryParams
      }, `CourseclassTeacher_${new Date().getTime()}.xlsx`)
    },
	
  }
};
</script>
